// 发送手机验证码成功
var sendMobileCodeSuccessSubmitCallback = function (data) {
    timeDisplay($('#requestVcodeTrigger'), 60);
};
var sendMobileCodeErrorSubmitCallback = function (data) {
    $('#requestVcodeTrigger').attr('disabled', false);
    if (typeof data.responseJSON == 'undefined') {
        formInlineTip($('#requestSubmit'), lang('tip.networkPoor'), 0);
    } else {
        formInlineTip($('#requestSubmit'), data.responseJSON.info, 0);
    }
};
// 校验手机验证码成功
var checkMobileTokenSuccessSubmitCallback = function (data) {
    window.location.href = data.data;
};
$(function () {
    $('#main-form-container .form-horizontal').inputValidate({
        submit: {
            query: '#requestSubmit'
        },
        inputs: [{
            query: '#requestMobile',
            regexp: window.commonRegexp.mobile,
            message: lang('tip.mobile'),
            emptyMessage: lang('tip.mobileNull')
        }, {
            query: '#requestVcode',
            regexp: window.commonRegexp.smsvcode,
            message: lang('dealer.verification'),
            emptyMessage: lang('tip.messages')
        }]
    });
    $('#main-form-container').inputValidate({
        submit: {
            query: '#requestVcodeTrigger'
        },
        inputs: [{
            query: '#requestMobile',
            regexp: window.commonRegexp.mobile,
            message: lang('tip.mobile'),
            emptyMessage: lang('tip.mobileNull')
        }]
    });
    // 重发验证码
    $('#requestVcodeTrigger').on('successSubmit.amos.inputValidate', function (e) {
        e.preventDefault();
        var submitBtn = $(this);
        if (submitBtn.attr('disabled') !== undefined) {
            return false;
        }
        submitBtn.attr('disabled', true);
        var params = {};
        params.mobile = $('#requestMobile').val();
        params.areaCode = $('.areaCodeValue').text().trim();
        ajaxRequest('/Home/Public/sendCode', params, 'post', sendMobileCodeSuccessSubmitCallback, sendMobileCodeErrorSubmitCallback);
    });
    // 提交验证码
    $('#requestSubmit').on('successSubmit.amos.inputValidate', function (e) {
        e.preventDefault();
        var submitBtn = $(this);
        if (submitBtn.attr('disabled') !== undefined) {
            return false;
        }
        submitBtn.attr('disabled', true);
        var params = {};
        params.mobile = $('#requestMobile').val();
        params.vcode = $('#requestVcode').val();
        params.areaCode = $('.areaCodeValue').text().trim();
        ajaxRequest('/Home/Public/checkCode', params, 'post', checkMobileTokenSuccessSubmitCallback, null, submitBtn);
    });
});
